package com.open4cn.simulator.parser.xrite.x7800;

import com.open4cn.simulator.answer.xrite.x7800.ApertureGetAnswer;
import com.open4cn.simulator.core.answer.AbstractAnswer;
import com.open4cn.simulator.core.answer.AnswerResponse;
import com.open4cn.simulator.core.ext.InMessage;
import com.open4cn.simulator.core.ext.OutMessage;
import com.open4cn.simulator.core.ext.XriteStatus;
import com.open4cn.simulator.core.parser.IInstructionParser;
import com.open4cn.simulator.core.parser.InstructionParserChain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-07-21 16:33
 */
public class ApertureGet implements IInstructionParser {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final String COMMAND = "aperture get";

    private ApertureGetAnswer answer = new ApertureGetAnswer();

    private XriteStatus xriteStatus;

    public ApertureGet(XriteStatus xriteStatus) {
        this.xriteStatus = xriteStatus;
        init();
    }

    private void init() {

    }

    @Override
    public Object parse(Object msg, InstructionParserChain chain) {
        InMessage inMessage = (InMessage) msg;
        if (!COMMAND.equals(inMessage.getCommand())) {
            return chain.filter(msg);
        }
        AnswerResponse response = this.answer.answer(xriteStatus, inMessage.getCommand());
        return new OutMessage(response.getData().toString());
    }

    @Override
    public List<AbstractAnswer> getAnswers() {
        return Arrays.asList(answer);
    }
}
